#include "TaylorSeries.h"


TaylorSeries::TaylorSeries(void)
{
}


TaylorSeries::~TaylorSeries(void)
{
}

double TaylorSeries::radius()
{
	// Use Cauchy Hadamard's formula to approximate the radius of convergence
	const int n = 50; // TODO: handle underflow/overflow 
	return 1/pow(abs(q(n)),1/double(n));
}

shared_ptr<Polynomial> TaylorSeries::truncate( unsigned int n )
{
	auto truncatedSeries = make_shared<Polynomial>();
	for(unsigned int k = 0; k <= n; k++){
		truncatedSeries->setCoefficient(k, q(k));
	}

	return truncatedSeries;
}
